<?php
Globals::requireClass('Controller');

class UploadController extends Controller
{
	protected $UserTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->UserTable = new UserTable($config);
	}
	
	public function indexAction(){
	    echo 'Upload';exit();
	}
	
	public function imgAction()
	{
	    $imgdata = $this->getParam('imgdata');
	    $imgtype = $this->getParam('imgtype');
	    
	    //创建目录
	    $uploaddir = '../upload/'.date("Ym").'/';
	    if (is_dir($uploaddir) == false)
	        mkdir($uploaddir,0777);
	    
        $filename = time().'.'.$imgtype;
        $fp = fopen($uploaddir.$filename, "w+");
        fwrite($fp, base64_decode($imgdata));
        fclose($fp);
	    
	    echo json_encode(array('returncode'=>'0'));
	    exit();
	}
	
	
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('UploadController', 'Controller');
